﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.ComponentModel.Composition;

namespace Kooboo.Commerce.Repositories
{
    [Export(typeof(IProductReview))]
    partial class ProductReview:Entity,IProductReview
    {
        

        IProduct _product;
        IProduct IProductReview.Product
        {
            get
            {
                if (this._product == null)
                {
                    this._product = this.DataContext.Products
                        .Where(i => i.Id == this.ProductId)
                        .FirstOrDefault();
                }

                return this._product;
            }
            set
            {

                if (value == null)
                {
                    throw new NullReferenceException("Product is null for ProductReview" + this.Id);
                }
                this._product = value;


                this.ProductId= value.Id;
            }
        }






        IOrder _order;
        IOrder IProductReview.Order
        {
            get
            {
                if (this._order == null)
                {
                    this._order = this.DataContext.Orders
                        .Where(i => i.Id == this.OrderId)
                        .FirstOrDefault();
                }

                return this._order;
            }
            set
            {

                if (value == null)
                {
                    throw new NullReferenceException("Order is null for ProductReview" + this.Id);
                }
                this._order = value;


                this.OrderId = value.Id;
            }
        }

     

        StarLevel IProductReview.Rate
        {
            get
            {
                return (StarLevel)this.Rate;
            }
            set
            {
                this.Rate = (int)value;
            }
        }

        ICustomer _customer;
        ICustomer IProductReview.Customer
        {
            get
            {
                if (this._customer == null)
                {
                    this._customer = this.DataContext.Customers.Where(i => i.Id == this.CustomerId).FirstOrDefault();
                }

                return this._customer;
            }
            set
            {
                this._customer = value;
                this.CustomerId = value.Id;
            }
        }

    }
}
